<template>
    <div style="margin-left: 20px;">
        <!-- <span>orderDetailName: {{orderDetailName}}</span> -->
        <span>订单号: {{ orderNumber }}</span><br><br>

        <el-card class="box-card" style="width: 80%;">
            <span>会员信息</span>

            <el-table :data="memberList" v-loading="listLoading" element-loading-text="Loading" border:true fit
                highlight-current-row stripe style="width: 80%">

                <el-table-column prop="memberId" label="会员ID" width="180">
                </el-table-column>

                <el-table-column prop="name" label="会员名称" width="180">
                </el-table-column>
                <el-table-column prop="phone" label="手机号" width="180">
                </el-table-column>

            </el-table>
        </el-card>


        <br><br>
        <el-card class="box-card" style="width: 80%;">
            <span>商品信息</span>
            <el-table :data="goodsList" v-loading="listLoading" element-loading-text="Loading" border:true fit
                highlight-current-row stripe style="width: 80%">

                <el-table-column prop="goodsListId" label="商品ID" width="180">
                </el-table-column>
                <el-table-column prop="goodsName" label="商品名称" width="180">
                </el-table-column>
                <el-table-column prop="price" label="价格" width="180">
                </el-table-column>
                <el-table-column prop="discounts" label="优惠金额" width="180">
                </el-table-column>
                <el-table-column prop="number" label="数量" width="180">
                </el-table-column>
            </el-table>
        </el-card>
        <br><br>

        <el-button type="primary" @click="handleBack()">返回</el-button>
    </div>
</template>

<script>
import { orderDetail } from '@/api/orderDetail';
import { getMemberInfoByAfter } from "@/api/afterSales";
import { getMemberInfoByOrder } from "@/api/orderList";

export default {


    filters: {
        statusFilter(status) {
            const statusMap = {
                published: "success",
                draft: "gray",
                deleted: "danger",
            };
            return statusMap[status];
        },
    },

    data() {
        return {
            memberList: [],
            memberInfo: {},
            goodsList: [],
            listLoading: true,

            form: {},
            orderNumber: this.$route.query.orderNumber,
            orderDetailName: this.$route.query.orderDetailName,

        };
    },

    created() {
        console.log("orderNumber", this.orderNumber);
        console.log("orderDetailName", this.orderDetailName);

        this.fetchData();
        this.memberDataFetch();
    },

    methods: {
        fetchData() {
            this.listLoading = true;
            orderDetail({
                orderNumber: this.orderNumber
            }).then((response) => {
                console.log('goodsList', response)
                this.goodsList = response.data;
                this.listLoading = false;
            });


        },
        // 会员详情
        memberDataFetch() {
            if (this.orderDetailName === '订单详情') {
                getMemberInfoByOrder({
                    orderNumber: this.orderNumber
                }).then((response) => {
                    console.log('memberInfo', response)
                    this.memberInfo = response.data;
                    console.log(this.memberInfo);
                    this.memberList = [this.memberInfo];
                });
            }
            else if (this.orderDetailName === '售后订单详情') {
                getMemberInfoByAfter({
                    orderNumber: this.orderNumber
                }).then((response) => {
                    console.log('memberInfo', response)
                    this.memberInfo = response.data;
                    console.log(this.memberInfo);
                    this.memberList = [this.memberInfo];
                });
            }
        },

        // 订单详情
        handleBack() {
            if (this.orderDetailName === '订单详情') {
                this.$router.push({ path: "/order/orderList" });
            } else if (this.orderDetailName === '售后订单详情') {
                this.$router.push({ path: "/order/afterSales" });
            }
        },

        // 生命周期钩子函数(vue对象创建完,自动调用该方法)
        created() {
            this.fetchData();
            //this.memberDataFetch();
        },
    }

}


</script>
